package com.lihan.controller;

import com.lihan.common.Result;
import com.lihan.model.entity.ChatMsg;
import com.lihan.model.vo.MessageVo;
import com.lihan.services.IChatService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.codehaus.plexus.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/chat")
@Api(tags = "聊天管理模块")
public class ChatController {

    @Resource
    private IChatService chatService;

    @GetMapping("/getUnReadMsgList")
    @ApiOperation("获取未签收的消息")
    public Result getUnReadMsgList(String acceptId){
        if(StringUtils.isBlank(acceptId)){
            return Result.errorMsg("接收者Id不能为空");
        }
        //根据接收者id获取未签收的消息
        List<ChatMsg> unReadMsgList = chatService.getUnReadMsgList(acceptId);
        return Result.ok(unReadMsgList);
    }

    @GetMapping("/getHistoryMsgList")
    @ApiOperation("获取全部已签收的消息")
    public Result getHistoryMsgList(String acceptId){
        if(StringUtils.isBlank(acceptId)){
            return Result.errorMsg("接收者Id不能为空");
        }
        //根据接收者id获取未签收的消息
        List<MessageVo> historyMsgList = chatService.getHistoryMsgList(acceptId);
        return Result.ok(historyMsgList);
    }

}
